package com.xinchen.quartz.core.test.CalendarExampleDemo;

import org.apache.log4j.Logger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.HolidayCalendar;

import java.util.Date;

import static org.quartz.CronScheduleBuilder.dailyAtHourAndMinute;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Description：
 *
 * @author Xin Chen
 * @version 1.0
 * @date 2016/12/14 16:07
 * @see 2016/12/14 16:07 Created
 ****************************************/
public class CalendarExample {
    private static Logger logger = Logger.getLogger(CalendarExample.class);

    public static void main(String[] args) throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        // define the job and tie it to our MyJob class
        JobDetail job = newJob(CalendarJob.class)
                .withIdentity("job1","group1")
                .build();

        HolidayCalendar calendar = new HolidayCalendar();
        Date date = new Date(1481803790862L);
        calendar.addExcludedDate(date);

        scheduler.addCalendar("myHolidays",calendar,false,false);

        Trigger t = newTrigger()
                .withIdentity("myTrigger","group1")
                .forJob("group1.job1")
                .withSchedule(dailyAtHourAndMinute(16, 18)) // execute job daily at 9:30
                .modifiedByCalendar("myHolidays") // but not on holidays
                .build();
        scheduler.scheduleJob(job,t);
    }
}
